package com.pn.controller;

import com.pn.entity.Result;
import com.pn.model.ProductType;
import com.pn.service.ProductTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/productCategory")
@RestController
public class ProductTypeController {

    @Autowired
    private ProductTypeService productTypeService;

    /**
     * 查询商品分类树
     * @return
     */
    @RequestMapping("/product-category-tree")
    public Result productCategoryTree() {
        //执行业务
        List<ProductType> typeTreeList = productTypeService.productTypeTree();
        //响应
        return Result.ok(typeTreeList);
    }

    /**
     * 校验分类编码是否已经存在
     * @param typeCode
     * @return
     */
    @RequestMapping("/verify-type-code")
    public Result checkTypeCode(String typeCode) {
        //执行业务
        Result result = productTypeService.checkTypeCode(typeCode);
        //响应
        return result;
    }
}
